<template>
	<view>
		<view class="pj">
			<view class="tit">
				<image :src="db.images[0]" mode="aspectFill" class="thumb"></image>
				<text>商品评价</text>
				<view class="xx">
					<block v-for="(ite,idx) of 5" :key="idx">
						<image @click="active = idx+1" v-if="active <= idx" :src="vuex_httpImageUrl && vuex_httpImageUrl+'static/common/xx.png'" mode="aspectFill"></image>
						<image @click="active = idx+1" v-else :src="vuex_httpImageUrl && vuex_httpImageUrl+'static/common/xx1.png'"></image>
					</block>
				</view>
			</view>
			<textarea v-model="textarea" placeholder="宝贝满足您的期待吗?说说你的使用心得,分享给想买的他们吧"></textarea>
			<view class="img">
				<image v-for="(item,index) in imgs" :key='index' :src="item" mode="aspectFill" @longpress='del(index)'></image>
				<image @click="chooseimg" :src="vuex_httpImageUrl && vuex_httpImageUrl+'static/common/uploadimg.png'" mode="aspectFill"></image>
			</view>
		</view>
		<view class="submit" @click="submit">确定并提交</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				active:0,
				db: {},
				textarea:'',
				imgs:[]
			};
		},
		onLoad(o) {
			this.db = JSON.parse(decodeURIComponent(o.db))
			// this.db = {
			// 	"address_id": 9,
			// 	"appraise_status": 0,
			// 	"appuser_id": 3,
			// 	"appuser_mobile": "",
			// 	"appuser_name": "",
			// 	"contime": "2022-01-19 12:10:10",
			// 	"createtime": "2022-01-19 09:16:45",
			// 	"goods_format": "长度",
			// 	"goods_id": 3,
			// 	"goods_name": "加特米",
			// 	"goods_num": 3,
			// 	"goods_price": "123.00",
			// 	"goods_total": "369.00",
			// 	"id": 26,
			// 	"images": [
			// 		"https://tcm.damiyaya.com/uploads/20211216/d6e46fc19a3a63706e3e2ca50e62e3b8.jpg"
			// 	],
			// 	"message": "",
			// 	"money": "369.00",
			// 	"order_status": "已收货",
			// 	"orderno": "854342_20220119091645_3",
			// 	"pay_trade_no": "805398_20220119091645_3",
			// 	"paytime": null,
			// 	"pushtime": "2022-01-19 11:45:27",
			// 	"receipt_address": "123",
			// 	"receipt_city": "",
			// 	"receipt_name": "123",
			// 	"receipt_phone": "13111111111",
			// 	"status": "3",
			// 	"tracking_num": "货物已经发送",
			// }
		},
		methods: {
			submit(){
				if(this.imgs.length){
					new Promise(resolve=>{
						let imgArr = [];
						this.imgs.forEach((item,index)=>{
							this.$u.utils.uploadFile(item).then(res=>{
								let thumb_image = JSON.parse(res).data.thumb_image
								imgArr.push(thumb_image)
								if(imgArr.length == this.imgs.length){
									resolve(imgArr)
								}
							})
						})
					}).then(res=>{
						this.$u.post('/order/inraise',{
							images:res.toString(),
							sys:this.textarea,
							level:this.active,
							order_id:this.db.id
						}).then(res=>{
							this.$u.toast(res.msg)
							setTimeout(_=>{
								uni.navigateBack()
							},700)
						})
					})
				}else{
					this.$u.post('/order/inraise',{
						images:'',
						sys:this.textarea,
						level:this.active,
						order_id:this.db.id
					}).then(res=>{
						this.$u.toast(res.msg)
						setTimeout(_=>{
							uni.navigateBack()
						},700)
					})
				}
			},
			del(index){
				uni.showModal({
					title:'提示',
					content:'确定删除该图?',
					success:res=>{
						if(res.confirm){
							this.imgs.splice(index,1)
						}
					}
				})
			},
			chooseimg(){
				uni.chooseImage({
					success:res=>{
						this.imgs = res.tempFilePaths
					}
				})
			}
		}
	}
</script>

<style lang="scss">
	.pj{
		width: 95%;
		margin: 30rpx auto;
		background-color: #FFFFFF;
		border-radius: 20rpx;
		padding: 35rpx;
		box-sizing: border-box;
		.tit{
			display: flex;
			align-items: center;
			margin-bottom: 20rpx;
			.xx{
				margin-left: 20rpx;
				image{
					width: 35rpx;
					height: 35rpx;
					margin-right: 20rpx;
				}
			}
			.thumb{
				width: 100rpx;
				height: 100rpx;
				border-radius: 10rpx;
				margin-right: 20rpx;
			}
		}
		textarea{
			width: 100%;
		}
		.img{
			image{
				width: 150rpx;
				height: 150rpx;
				margin-right: 20rpx;
				margin-bottom: 20rpx;
			}
		}
	}
	.submit{
		text-align: center;
		padding: 20rpx 0;
	}
	
</style>
